<template>
	<view class="pharmacist-wrap" v-if="doctorInfo">
		<view class="index-bg" style="height: 310rpx;"></view>
		<view class="pharmacist-header" @click="gotoRouter('/pages-doctor/auth/auth?doctorType=2')">
			<image class="pharmacist-header-img" :src="doctorInfo.picture"></image>
			<view class="pharmacist-header-info">
				<view class="outer1">
					<text lines="1" class="word1">{{ doctorInfo.doctorName }}</text>
					<text lines="1" class="info1">{{ jobGradeConfig[doctorInfo.jobGrade] }}</text>
				</view>
				<text lines="1" decode="true" class="info2 nowrap">{{ doctorInfo.hospName }}&nbsp;&nbsp;{{ doctorInfo.departmentName }}</text>
			</view>
			<view class="pharmacist-header-auth">{{ checkStatusConfig[doctorInfo.checkStatus] }}</view>
		</view>

		<view class="pharmacist-list">
			<view class="pharmacist-item" @click="gotoRouter('/pages-doctor/auth/auth?doctorType=2')">
				<image src="http://k8s.vendingtech.vip/images/my_auth@2x.png" class="pharmacist-item-icon"></image>
				<view class="pharmacist-item-word">我的认证</view>
			</view>
			<view class="pharmacist-item" @click="gotoRouter('/pages/accountSwitch/accountSwitch?pageType=2')">
				<image src="http://k8s.vendingtech.vip/images/account_cut@2x.png" class="pharmacist-item-icon"></image>
				<view class="pharmacist-item-word">账户切换</view>
			</view>
		</view>

		<view class="pharmacist-group">
			<u-tabs v-model="activeTab" :scroll="false" :tabs="['待审核处方', '历史处方']" @change="tabChange"></u-tabs>

			<scroll-view show-scrollbar="false" class="pharmacist-scroller" scroll-y @scrolltolower="scrollLoading()">
				<view class="pharmacist-presc-list">
					<u-presc-item
						v-for="(item, index) in dataList"
						:key="index"
						:data="item"
						@click="gotoRouter('/pages-doctor/prescInfo/prescInfo?id=' + item.id + '&role=2')"
						type="1"
						@clickOne="gotoRouter('/pages-doctor/prescInfo/prescInfo?id=' + item.id + '&role=2')"
					></u-presc-item>
					<u-empty-state v-if="dataTotalPage == 0" value="暂无相关处方"></u-empty-state>
				</view>
				<uni-load-more v-if="dataTotalPage > 1" :status="dataLoading"></uni-load-more>
			</scroll-view>
		</view>
	</view>
</template>

<script>
import uTab from '@/components/u-tabs/u-tabs.vue';
import uPrescItem from '@/components/u-presc-item/u-presc-item.vue';
import uniLoadMore from '@/components/uni/uni-load-more/uni-load-more.vue';
import uEmptyState from '@/components/u-empty-state/u-empty-state.vue';
export default {
	components: {
		uTab,
		uPrescItem,
		uniLoadMore,
		uEmptyState
	},
	data() {
		return {
			doctorInfo: null,
			hospital: null,
			activeTab: 0,
			pageNo: 1,
			pageSize: 20,
			dataTotal: 0, //数据总数
			dataTotalPage: 1, //数据总分页
			dataLoading: 'loading', //数据加载
			dataList: []
		};
	},
	onLoad(option) {
		this.getDoctorInfo();
	},
	onShow() {
		this.initData();
	},
	methods: {
		tabChange(e) {
			this.activeTab = e;
			this.initData();
		},

		initData() {
			this.pageNo = 1;
			this.dataList = [];
			this.dataTotalPage = 1;
			this.dataTotal = 0;
			this.scrollLoading();
		},

		//获取医生/药师个人信息
		getDoctorInfo() {
			this.$api.getDoctorInfo({}).then(res => {
				if (res.code == 200) {
					this.doctorInfo = res.result;
					this.hospital = res.result.hosptail;
				}
			});
		},

		//药师待审核处方
		drugRecipePage() {
			this.$api
				.drugRecipePage({
					params: {
						pageNo: this.pageNo,
						pageSize: this.pageSize
					}
				})
				.then(res => {
					if (res.code == 200) {
						res.result.records.forEach(key => {
							key.recipeDetailDTO = JSON.parse(key.content);
						});
						this.dataTotalPage = res.result.pages;
						this.dataTotal = res.result.total;
						if (this.pageNo == 1) {
							this.dataList = res.result.records;
						} else {
							this.dataList = this.dataList.concat(res.result.records);
						}

						if (res.result.current >= res.result.pages) {
							this.dataLoading = 'noMore';
						} else {
							this.dataLoading = 'loading';
						}
						this.pageNo++;
					} else {
						uni.showToast({
							title: res.message,
							icon: 'none'
						});
					}
				});
		},

		//药师历史处方
		checkedRecipePage() {
			this.$api
				.checkedRecipePage({
					params: {
						pageNo: this.pageNo,
						pageSize: this.pageSize
					}
				})
				.then(res => {
					if (res.code == 200) {
						res.result.records.forEach(key => {
							key.recipeDetailDTO = JSON.parse(key.content);
						});
						this.dataTotalPage = res.result.pages;
						this.dataTotal = res.result.total;
						if (this.pageNo == 1) {
							this.dataList = res.result.records;
						} else {
							this.dataList = this.dataList.concat(res.result.records);
						}

						if (res.result.current >= res.result.pages) {
							this.dataLoading = 'noMore';
						} else {
							this.dataLoading = 'loading';
						}
						this.pageNo++;
					} else {
						uni.showToast({
							title: res.message,
							icon: 'none'
						});
					}
				});
		},

		//滚动加载
		scrollLoading() {
			if (this.pageNo <= this.dataTotalPage) {
				switch (this.activeTab) {
					case 0:
						this.drugRecipePage();
						break;
					case 1:
						this.checkedRecipePage();
						break;
					default:
						break;
				}
			}
		}
	}
};
</script>

<style lang="less">
@import './pharmacist.less';
</style>
